<extend name="Shops:layout" />
<block name="content">
<style type="text/css">
.wst-pagination{
  margin-top: 10px;
  text-align: center;
  height: 25px;
  line-height: 25px;
}
.wst-current{
  background-color: rgb(226, 62, 61);
  color: #fff;
  padding: 0 12px;
  border-radius: 2px;
  height: 26px;
  line-height: 26px;
  display: inline-block;
  vertical-align: top;
  font-size: 12px;
}
.wst-num{
  background-color: #f1eff0;
  padding: 0 12px;
  border-radius: 2px; 
  margin: 0 3px 6px;
  height: 26px;
  line-height: 26px;
  text-decoration: none;
  color: #666;
  display: inline-block;
  vertical-align: top;
  font-size: 12px;
}
.wst-next,.wst-prev{
  background-color: #f1eff0;
  padding: 0 12px;
  border-radius: 2px;

  height: 26px;
  line-height: 26px;
  text-decoration: none;
  color: #666;
  display: inline-block;
  vertical-align: top;
  font-size: 12px;
}
.anniu{
  border:1px solid #ffffff;height:25px;width:100px;background-color:#e23e3d;color:#ffffff;cursor: pointer;text-align: center;line-height: 25px;
}
</style>
<script src="__PUBLIC__/plugins/plugins/plugins.js"></script>
<script>
$(document).ready(function(){
    <notempty name='shopCatId1'>
    getShopCatListForAppraises('{$shopCatId1}','{$shopCatId2}');
    </notempty>
});
</script>
<script>
     $(function(){
     layer.config({
                extend: 'extend/layer.ext.js'
      });
  })
   </script>
   <script>
   function del(id){
  layer.confirm("您确定要删除该中奖纪录吗",{icon: 3, title:'系统提示'},function(tips){
    $.post(Think.U('Home/Ggk/delcheat'),{id:id},function(data,textStatus){
      layer.close(tips);
        var json = WST.toJson(data);
        if(json.status=='1'){
          WST.msg('操作成功！', {icon: 1},function(){
            location.reload();
          });
        }else{
          WST.msg('操作失败', {icon: 5});
        }
    });
  });
}



   function checksn(id){
     var sn=$('input[name="sn"]').val();
       if (!sn) {
        layer.msg('你没有填写中奖码');
        return;
      }
      $.post("{:U('Home/Ggk/checksn')}",{id:id,sn:sn},function(data,textStatus){
        var json = WST.toJson(data);
          switch(json.status){
            case 1:
            layer.confirm('<b style="color:red;">'+sn+'</b>中奖码可以使用。<br>奖品：<b style="color:red;">'+json.title+'</b>尚未兑奖。', {btn: ['确认兑奖','取消兑奖']},
              function(){
                runcheat(json.id);
               },
              function(){
                layer.closeAll();
              })
            break;
            case 2:
            layer.msg("查询不到该中奖码",{time:2500});
            break;
            case 4:
            layer.msg('该中奖码已兑奖');
            break;
          }
        });
   }

   </script>
<div class="wst-body"> 
<div class='wst-page-header'>卖家中心 > 刮刮卡中奖管理</div>
<div class='wst-page-content'>
 <input type='hidden' id='admin_check' name='admin_check' value='1'/> 
    <button class="anniu" onclick="window.location.href='/Home/Ggk/manage.html?id={$num["id"]}'">全部</button>
    <button class="anniu" onclick="window.location.href='/Home/Ggk/manage.html?id={$num["id"]}&sendstutas=2'">已发送奖品</button>
    <button class="anniu" onclick="window.location.href='/Home/Ggk/manage.html?id={$num["id"]}&sendstutas=1'">未发送奖品</button>
    
    <button class="anniu" style="float: right;" onclick="window.location.href='/Home/Ggk/shoplist.html'">返回</button>
    
      <a style="float: right; margin-right: 10px; color: #ffffff" class="anniu" href ="{:U('Home/Ggk/exportexcel',array('id'=>$num['id']))}">导出中奖数据</a>   

    <div style="margin-top: 10px;">
      <input type="text" name="sn" > <button type="button" class="anniu" onclick="javascript:checksn({$num['id']})">查询中奖码</button>
      <button type="button" class="anniu" id="getallid">批量发奖</button> 
    <span>本次活动奖品总数为：<b style="color:red;">{$num['jpallnums']}</b></span> <span>中奖人数：<b style="color:red;">{$num['zjnums']}</b></span> <span>已发奖品：<b style="color:red;">{$num['sendnums']}</b></span>
        
  
   <table class='wst-list' style="margin:0 auto;">
          <thead>
             <tr>
               <th width="50"><input type="checkbox" id="ckAll">序号</th>
               <th width='200'>SN码（中奖码）</th>
               <th width="100">奖项</th>
               <th width="100">显示否已发奖品</th>
               <th width="120">奖品发送时间</th>
               <th width="100">用户名称</th>
               <th>收货信息</th>
               <th width='50' style="text-align: center;">操作</th>
             </tr>
           </thead>
           <tbody>
           <volist name='list' id='vo'>
           <tr>
           <td>
           <?php if($vo['sendstutas']=='0'){ ?>
           <?php if($vo['addressId']!='0'){ ?>
           <input type="checkbox" name="sub" value="{$vo['id']}">
           <?php } ?>
           <?php } ?>
           {$vo['id']}
           </td>
             <td>
              {$vo['sn']}
             </td>
           <td>
         {$vo['jp']}
           </td>
           <td>
             <?php 
             switch($vo['sendstutas']){
              case '0':
              echo "<b>准备中</b>";
              break;
              case '1':
              echo "<b style='display: block;height: 20px;'>配送中</b>";
              $id=$vo["id"];
              echo "<span style='cursor:pointer; ' onclick='javascript:checkml($id)'>查看物流</span>";
              break;
              case '2':
              echo "<b style='display: block;height: 20px;'>已签收</b>";
              $id=$vo["id"];
              echo "<span style='cursor:pointer; ' onclick='javascript:checkml($id)'>查看物流</span>";
              break;
              case '3':
              echo "<b>已其他方式发奖</b>";
              break;
             }
             ?>
           </td>
           <td>
             <?php if((int)$vo['sendtime']==0){
             echo "待定";
             }else{ ?>
             {$vo['sendtime']|date='Y-m-d H:i',###}

             <?php } ?>
           </td>
          <td>{$vo['userName']}</td>
          <td id="ressId{$vo['id']}" value="{$vo['addressId']}">
            <?php if($vo['addressId']!=0){ ?>
            {$vo['ress'][str]}
            <?php }else{ 
            echo "<b>未选择地址</b>";
            } ?>

          </td>
           <td style="width: 150px;text-align: center;font-size: 15px;"> 
           <?php if($vo['sendstutas']==0){ ?>
           <a style="cursor: pointer;" onclick="javascript:runcheat({$vo['id']})">[发奖]</a> |
           <?php } ?>
           <a href="/Home/Ggk/update.html?id={$vo['id']}">[编辑]</a> |
           <a style="cursor: pointer;" onclick="javascript:del({$vo['id']})">[删除]</a>
           </td>
           </tr>
           </volist>
           <tr>
             <td colspan='8' class="nav_down" >{$show}</td>
           </tr>
           </tbody>
        </table>
</div>
</div>
<script>
  $("#ckAll").click(function() {
    $("input[name='sub']").prop("checked", this.checked);
  });
  
  $("input[name='sub']").click(function() {
    var $subs = $("input[name='sub']");
    $("#ckAll").prop("checked" , $subs.length == $subs.filter(":checked").length ? true :false);
  });


  $("#getallid").click(function(){
    var str=[];
    var it ='';

    $('input[name="sub"]:checked').each(function(){
     it+="<tr><td id='zjid' value="+$(this).val()+">"+$(this).val()+"</td><td><input type='text' name='kddh[]' id='kddh'></td></tr>";
     str.push($(this).val());
    });
    if (str=='') {
      layer.msg('没有勾选任何选项');
    }else{

      var title = "<table id='kdtable' class='wst-list'><thead><tr><td id='wuliutd' colspan='2'></td></tr><tr><th>序号</th><th>快递单号</th></tr></thead><tbody>";
      var footer = "<tr><td colspan='2'><button onclick='javascript:sendallid()'>确定发奖</button></td></tr></tbody></table>"
      layer.open({
          type: 1,
          skin: 'layui-layer-rim', //加上边框
          area: ['450px', '550px'], //宽高
          content: title+it+footer,
        });
      }
      getwuliu();
    })

  function getwuliu(id){
      $.post("/Home/Ggk/getwuliu.html",function(data){
        if (data.status==1) {
          var strtop = "选择物流公司：<select id='wuliu'><option value='kong'>选择物流</option>";
          var strfooter = "</select>";
          var strcon='';
          var json = eval(data.str);
          $.each(json,function(key,value){
            strcon+="<option value='"+value.id+"'>"+value.expressCompany+"</option>";
          })
          var str = strtop+strcon+strfooter;
        }else{
          var str = "<b>您没有设置物流</b><input type='hidden' id='wuliu' value='kong'>";
        }

        $('#wuliutd').append(str);
      })
  }

  function sendallid(){
    var wuliu = $('#wuliu').val();
    if (wuliu=='kong') {
      layer.msg('您没有选择物流公司');
      return false;
    }else{
      var kddh=[];
      var zjid=[];
      var r=0;
      $('#kdtable input').each(function(){
        if (!$(this).val()) {
           r=r+1;
        }
        kddh.push($(this).val());
      })

      if (r>0) {
        layer.msg('有快递单号为空');
        return;
      }
      $('#kdtable #zjid').each(function(){
        zjid.push($(this).attr('value'));
      })

      $.ajax({
        url:"/Home/Ggk/kdsendstutas.html",
        data:{
          id:zjid,
          kdnum:kddh,
          wuliu:wuliu
        },type:'post',
        beforeSend:function(){
          layer.load();
        },
        success:function(data){
          layer.closeAll();
          if (data.status==1) {
            layer.msg('提交成功',{icon:1});
            location.reload();
          }else{
            layer.msg('出现错误,请稍后再试',{icon:2});
          }
        }

      })
    }
  }


  function runcheat(id){ 
  layer.confirm("寄送奖品还显示其他方式发奖？",{icon: 3, title:'系统提示',btn: ['寄送', '其他'],btn2:function(){
    $.post(Think.U('Home/Ggk/sendstutas'),{id:id},function(data,textStatus){
        if(data.status=='1'){
          WST.msg('操作成功！', {icon: 1,time:2000},function(){
            location.reload();
          });
        }else{
          WST.msg('操作失败', {icon: 5});
        }
    });
  }
},
    function(){
      var ressId= $('#ressId'+id).attr('value');

        if (ressId=='0') {
          layer.msg('该用户没有选择收货地址',{icon:2});
          return;
        }
      var str = "<table id='kdtable' class='wst-list'><tr><td id='wuliutd' colspan='2'></td></tr><tr><td id='zjid' value="+id+">快递单号：</td><td><input tyoe='text' name='kdnum' ></td></tr><tr><td colspan='2'><button style='width=100px;display:block;margin:0 auto;' type='button' onclick='sendallid();'>确认发奖</button></td></tr></table>";
      layer.open({
          title:"填写快递单号",
          type: 1,
          skin: 'layui-layer-rim', //加上边框
          area: ['500px', '200px'], //宽高
          content: str,
        });
      getwuliu();
  });
}

  function checkml(id){
        $.ajax({
          url:"/Home/Ggk/getwuliumsg.html",
          data:{
            id:id
          },type:'get',
          beforeSend:function(){
            layer.load();
          },
          success:function(data){
            layer.closeAll();
            
            if(data.status!=2){
            var top = "<div style='padding: 10px; text-align: center;'>快递公司：<b style='color:blue;padding-right: 10px;'>"+data.gs+"</b> 快递单号：<b style='color:red;padding-right: 10px;'>"+data.nu+"</b><b style='color:blue;padding-right: 10px;'>"+data.state+"</b></div>";
              var title="<table class='wst-list'><thead><tr><th>时间</th><th>地点和跟踪进度</th></tr></thead><tbody>";
              var footer = "</tbody></table>";
              var con ='';
               if (data.msg) {
                  var json = eval(data.msg);
                  $.each(json,function(key,value){
                    con+="<tr><td>"+value.time+"</td><td>"+value.context+"</td></tr>";
                  })
                 }
              layer.open({
              title :'查看物流',
              type: 1,
              skin: 'layui-layer-rim', //加上边框
              area: ['650px', '500px'], //宽高
              content: top+title+con+footer,
            });
            }else{  
              layer.msg('该快递单号出错',{icon:2});
              return;}
              

          }
        })
      }
</script>
</block> 